import request from '@/utils/request'

// 查询设备列表
export function listDevice(query) {
  return request({
    url: '/system/device/list',
    method: 'get',
    params: query
  })
}

// 查询设备详细
export function getDevice(id) {
  return request({
    url: '/system/device/' + id,
    method: 'get'
  })
}

// 查询设备详细
export function getDeviceByMacAndWay(query) {
  return request({
    url: '/system/device/byMacAndWay',
    method: 'get',
    params: query
  })
}

// 新增设备
export function addDevice(data) {
  return request({
    url: '/system/device',
    method: 'post',
    data: data
  })
}

// 修改设备
export function updateDevice(data) {
  return request({
    url: '/system/device',
    method: 'put',
    data: data
  })
}

// 删除设备
export function delDevice(query) {
  return request({
    url: '/system/device/delete',
    method: 'delete',
    params: query
  })
}

// 导出家庭
export function exportDevice(query) {
  return request({
    url: '/system/device/export',
    method: 'get',
    params: query
  })
}

// 查询设备详细
export function getDeviceCount() {
  return request({
    url: '/system/device/getDeviceCount',
    method: 'get'
  })
}

// 查询设备列表
export function listDeviceAction(query) {
  return request({
    url: '/system/device/getDeviceAction',
    method: 'get',
    params: query
  })
}

// 控制设备
export function sendUrl(cmd) {
  return request({
    url: '/system/device/cmd',
    method: 'get',
    params: cmd
  })
}

// 查询家庭下的zigbee设备
export function getDeviceListByHomeId(query) {
  return request({
    url: '/system/device/listByHomeId',
    method: 'get',
    params: query
  })
}

/**
 *
 * @param actions 对象数组
 * @returns {string}
 */
export function fetchStatus(actions, deviceType) {
  let returnArr = []
  if (!actions || actions === '') {
    console.log('aaaa')
    returnArr.push(`<div class="myTagClose">`)
    returnArr.push(`未知`)
    returnArr.push(`</div>`)
    return returnArr.join('')
  }
  let myActions = JSON.parse(JSON.stringify(actions))
  let myArr = []
  let result = []

  if (!deviceType || deviceType === '') {
    returnArr.push(`<div class="myTagClose">`)
    returnArr.push(`未知`)
    returnArr.push(`</div>`)
    return returnArr.join('')
  }

  switch (deviceType.split('_')[0]) {
    case '0FBEA002':  //温湿度传感器
    case '0FB40102':
      myArr = ['temp', 'humidity', 'dianya']
      result = getDeviceActionStatus(myActions, myArr)
      returnArr.push(`<div class="myTagLight">`)
      returnArr.push(`温度${result[0].value}°C `)
      returnArr.push(`湿度${result[1].value}% `)
      returnArr.push(`电量${getDianLiang(result[2].value)}`)
      returnArr.push(`</div>`)
      break
    case '0FAA0D02':  //双色温驱动
      myArr = ['switchState', 'setColorTemperature', 'setBrightness', 'mode', 'duration']
      result = getDeviceActionStatus(myActions, myArr)
      if (result[0].value === '01') {
        returnArr.push(`<div class="myTagOpen">`)
        returnArr.push(`色温${result[1].value}% `)
        returnArr.push(`亮度${result[2].value}% `)
        // returnArr.push(`${getShuangSeWemMode(result[3].value)} `)
        returnArr.push(`${result[4].value}档 `)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`关`)
      }
      returnArr.push(`</div>`)
      break
    case '0FAA0D03':    //单色温驱动
      myArr = ['switchState', 'setBrightness', 'mode', 'duration']
      result = getDeviceActionStatus(myActions, myArr)
      if (result[0].value === '01') {
        returnArr.push(`<div class="myTagOpen">`)
        returnArr.push(`亮度${result[1].value}% `)
        // returnArr.push(`${getShuangSeWemMode(result[3].value)} `)
        returnArr.push(`${result[3].value}档`)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`关`)
      }
      returnArr.push(`</div>`)
      break
    case '0FAA0D04':    //开关控制盒
    case '0FAA0502':    //一路面板
    case '0FAA0504':    //一路联控面板
    case '0FAA0602':    //二路面板
    case '0FAA0604':    //二路联控面板
    case '0FAA0702':    //三路面板
    case '0FAA0704':    //三路联控面板
    case '0FAA0804':    //四路联控面板
    case '0FAA0213':    //机械手控制器
    case '0FAA0902':    //声光报警器
    case '0FAA8106':    //插卡取电
    case '0FAA8A09':    //多功能开关
    case '0FAA8A0A':    //卓悦面板
    case '0FAB0202':    //八路控制器
    case '0FAB0602':    //四路面板(雷达功能)
    case '0FAA0202':    //强电控制盒
    case '0FAA0203':    //弱电控制盒
    case '0FE60211':    //平移开窗器
    case '0FAA0211':    //推拉开窗器
    case '0FAA0511':    //移动开关插座
    case '0FE60206':    //取暖器（红杉树）现阶段只取开关, 其他状态后期补齐
      myArr = ['switchState']
      result = getDeviceActionStatus(myActions, myArr)
      if (result[0].value === '01') {
        returnArr.push(`<div class="myTagOpen">`)
        returnArr.push(`开`)
      } else if (result[0].value === '02') {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`关`)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`未知`)
      }
      returnArr.push(`</div>`)
      break
    case '0FC80402':    //10A计量插座
    case '0FC80403':    //16A计量插座
      myArr = ['switchState', 'dianliang', 'dianya', 'dianliu', 'gonglv']
      result = getDeviceActionStatus(myActions, myArr)
      if (result[0].value === '01') {
        returnArr.push(`<div class="myTagOpen">`)
        returnArr.push(`电量${result[1].value}Kwh `)
        returnArr.push(`电压${result[2].value}V `)
        returnArr.push(`电流${result[3].value}A `)
        returnArr.push(`功率${result[4].value}W `)
      } else if (result[0].value === '02') {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`关`)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`未知`)
      }
      returnArr.push(`</div>`)
      break
    case '0FAA0E02':    //智能窗帘
    case '0FE60209':    //静音窗帘(丙申)
      myArr = ['position']
      result = getDeviceActionStatus(myActions, myArr)
      if (result[0].value) {
        returnArr.push(`<div class="myTagLight">`)
        returnArr.push(`开合度${parseInt(result[0].value, 16)}% `)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`未知`)
      }
      returnArr.push(`</div>`)
      break
    case '0FBE0102':  //门磁
      myArr = ['fangChaiState', 'alarmState', 'dianya']
      result = getDeviceActionStatus(myActions, myArr)
      if (result[0].value) {
        returnArr.push(`<div class="myTagOpen">`)
        if (result[0].value === '01') {
          returnArr.push(`防拆开关故障 `)
        } else if (result[0].value === '02') {
          returnArr.push(`防拆开关正常 `)
        }
        returnArr.push(`${result[1].value === '01' ? '已开启' : '已关闭'} `)
        returnArr.push(`电量${getDianLiang(result[2].value)}`)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`未知`)
      }
      returnArr.push(`</div>`)
      break
    case '0FBE0402':  //人体红外
      myArr = ['fangChaiState', 'alarmState', 'dianya']
      result = getDeviceActionStatus(myActions, myArr)
      if (result[0].value) {
        returnArr.push(`<div class="myTagLight">`)
        if (result[0].value === '01') {
          returnArr.push(`防拆开关故障 `)
        } else if (result[0].value === '02') {
          returnArr.push(`防拆开关正常 `)
        }
        returnArr.push(`${result[1].value === '01' ? '感应有人' : '感应无人'} `)
        returnArr.push(`电量${getDianLiang(result[2].value)}`)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`未知`)
      }
      returnArr.push(`</div>`)
      break
    case '0FBF0202':  //德施曼锁
    case '0FBE0202':  //指纹锁（聪明屋）
    case '0FBE0203':  //指纹锁（六孚）
      myArr = ['dianya']
      result = getDeviceActionStatus(myActions, myArr)
      if (result[0].value) {
        returnArr.push(`<div class="myTagOpen">`)
        returnArr.push(`电量${getDianLiang(result[0].value)}%`)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`未知`)
      }
      returnArr.push(`</div>`)
      break
    case '0FAA0B02':  //灯带1.0
    case '0FAA0B03':  //灯带2.0
      myArr = ['switchState']
      result = getDeviceActionStatus(myActions, myArr)
      if (result[0].value === '01') {
        returnArr.push(`<div class="myTagOpen">`)
        returnArr.push(`开`)
      } else if (result[0].value === '02') {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`关`)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`未知`)
      }
      returnArr.push(`</div>`)
      break
    case '0FBE0702':  //烟雾探测器(弱电)
    case '0FBE0502':  //水浸传感器
      myArr = ['fangChaiState', 'alarmState', 'dianya']
      result = getDeviceActionStatus(myActions, myArr)
      if (result[0].value) {
        returnArr.push(`<div class="myTagLight">`)
        if (result[0].value === '01') {
          returnArr.push(`防拆开关故障 `)
        } else if (result[0].value === '02') {
          returnArr.push(`防拆开关正常 `)
        }
        returnArr.push(`${result[1].value === '01' ? '检测报警' : '检测正常'} `)
        returnArr.push(`电量${getDianLiang(result[2].value)}`)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`未知`)
      }
      returnArr.push(`</div>`)
      break
    case  '0FAA8102':   //燃气探测器(强电)
      myArr = ['alarmState']
      result = getDeviceActionStatus(myActions, myArr)
      if (result[0].value) {
        returnArr.push(`<div class="myTagLight">`)
        returnArr.push(`${result[0].value === '01' ? '检测报警' : '检测正常'} `)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`未知`)
      }
      returnArr.push(`</div>`)
      break
    case '0FAC0502':  // 智能空调面板
      // 空调
      // debugger
      if (deviceType.split('_')[1] === '1') {
        myArr = ['nowTemplate', 'nowHumidity', 'switchState', 'mode', 'temperature', 'fanSpeed']
        result = getDeviceActionStatus(myActions, myArr)
        if (result[2].value === '01') {
          returnArr.push(`<div class="myTagLight">`)
          returnArr.push(`室内温度${result[0].value}°C `)
          returnArr.push(`湿度${result[1].value}% | `)
          returnArr.push(`${getAirConditionMode(result[3].value)} `)
          returnArr.push(`${result[4].value}°C `)
          returnArr.push(`${getAirConditionFanSpeed(result[5].value)} `)
        } else if (result[2].value === '02') {
          returnArr.push(`<div class="myTagLight">`)
          returnArr.push(`室内温度${result[0].value}°C `)
          returnArr.push(`湿度${result[1].value}% 已关闭`)
        } else {
          returnArr.push(`<div class="myTagClose">`)
          returnArr.push(`未知`)
        }
        returnArr.push(`</div>`)
      } else if (deviceType.split('_')[1] === '2') {
        // 地暖
        myArr = ['nowTemplate', 'nowHumidity', 'switchState', 'temperature']
        result = getDeviceActionStatus(myActions, myArr)
        if (result[2].value === '01') {
          returnArr.push(`<div class="myTagLight">`)
          returnArr.push(`室内温度${result[0].value}°C `)
          returnArr.push(`湿度${result[1].value}% | `)
          returnArr.push(`${result[3].value}°C `)
        } else if (result[2].value === '02') {
          returnArr.push(`<div class="myTagLight">`)
          returnArr.push(`室内温度${result[0].value}°C `)
          returnArr.push(`湿度${result[1].value}% | 已关闭`)
        } else {
          returnArr.push(`<div class="myTagClose">`)
          returnArr.push(`未知`)
        }
        returnArr.push(`</div>`)
      } else if (deviceType.split('_')[1] === '3') {
        // 新风
        myArr = ['nowTemplate', 'nowHumidity', 'switchState', 'fanSpeed']
        result = getDeviceActionStatus(myActions, myArr)
        if (result[2].value === '01') {
          returnArr.push(`<div class="myTagLight">`)
          returnArr.push(`室内温度${result[0].value}°C `)
          returnArr.push(`湿度${result[1].value}% | `)
          returnArr.push(`${getAirConditionFanSpeed(result[3].value)} `)
        } else if (result[2].value === '02') {
          returnArr.push(`<div class="myTagLight">`)
          returnArr.push(`室内温度${result[0].value}°C `)
          returnArr.push(`湿度${result[1].value}% | 已关闭`)
        } else {
          returnArr.push(`<div class="myTagClose">`)
          returnArr.push(`未知`)
        }
        returnArr.push(`</div>`)
      }
      break
    case '0FAA0C02':    //晾衣架
      myArr = ['lightState', 'modeState']
      result = getDeviceActionStatus(myActions, myArr)
      returnArr.push(`<div class="myTagLight">`)
      returnArr.push(`${result[0].value === '01' ? '照明已开启' : '照明已关闭'} `)
      returnArr.push(`${getLiangYiJiaMode(result[1].value)} `)
      returnArr.push(`</div>`)
      break
    case '0FAA8105':    //86型人体感应面板
    case '0FAA8103':    //一氧化碳探测器 (可能有问题)
      myArr = ['alarmState', 'sosState']
      result = getDeviceActionStatus(myActions, myArr)
      returnArr.push(`<div class="myTagLight">`)
      returnArr.push(`${result[0].value === '01' ? '检测有人' : '检测无人'} `)
      if (result[1].value === '01') {
        returnArr.push(`SOS报警中`)
      }

      returnArr.push(`</div>`)
      break
    case '0FAC0202':    //空调面板
      myArr = ['switchState']
      result = getDeviceActionStatus(myActions, myArr)
      if (result[0].value === '01') {
        returnArr.push(`<div class="myTagOpen">`)
        returnArr.push(`开`)
      } else if (result[0].value === '02') {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`关`)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`未知`)
      }
      returnArr.push(`</div>`)
      break
    case '0FAC0302':    //地暖面板
      myArr = ['switchState']
      result = getDeviceActionStatus(myActions, myArr)
      if (result[0].value === '01') {
        returnArr.push(`<div class="myTagOpen">`)
        returnArr.push(`开`)
      } else if (result[0].value === '02') {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`关`)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`未知`)
      }
      returnArr.push(`</div>`)
      break
    // case '0FAA8104':  //烟雾探测器(强电)
    // case '0FAA8A07':  //魔幻场景
    // case '0FAA8A08':  //随意贴
    // case '0FAA8A02':  //场景面板
    // case '0FAA8A03':  //液晶场景控制器
    // case '0FAA8A04':  //智能场景面板
    // case '0FAA8A05':  //六路场景（极享系列）
    // case '0FAA8A06':  //四路场景（极光系列）
    // case '0FAA8A10':  //六路场景
    // case '0FE60203':  //音乐背景器
    // case '0FE60202':  //红外学习仪
    // case '0FE60207':  //中央空调控制器
    // case '0FAD0207':  //智能空调控制器
    // case '0FBE0802':  //魔幻开关
    //   break
    default:
      returnArr.push(`<div class="myTagClose">`)
      returnArr.push(`未知`)
      returnArr.push(`</div>`)
      break
  }

  return returnArr.join('')
}

/**
 *
 * @param actions 对象数组
 * @returns {string}
 */
export function smartFetchStatus(actions, deviceType) {
  console.log(actions)
  let returnArr = []
  if (!actions || actions === '') {
    console.log('aaaa')
    returnArr.push(`<div class="myTagClose">`)
    returnArr.push(`未知`)
    returnArr.push(`</div>`)
    return returnArr.join('')
  }
  let myActions = JSON.parse(actions)
  let myArr = []
  let result = []

  if (!deviceType || deviceType === '') {
    returnArr.push(`<div class="myTagClose">`)
    returnArr.push(`未知`)
    returnArr.push(`</div>`)
    return returnArr.join('')
  }

  switch (deviceType.split('_')[0]) {
    case '0FBEA002':  //温湿度传感器
    case '0FB40102':
      myArr = ['temp', 'humidity', 'dianya']
      result = getDeviceActionStatus(myActions, myArr)
      returnArr.push(`<div class="myTagLight">`)
      returnArr.push(`温度${result[0].value}°C `)
      returnArr.push(`湿度${result[1].value}% `)
      returnArr.push(`电量${getDianLiang(result[2].value)}`)
      returnArr.push(`</div>`)
      break
    case '0FAA0D02':  //双色温驱动
      myArr = ['switchState', 'setColorTemperature', 'setBrightness', 'mode', 'duration']
      result = getDeviceActionStatus(myActions, myArr)
      if (result[0].value === '01') {
        returnArr.push(`<div class="myTagOpen">`)
        returnArr.push(`色温${result[1].value}% `)
        returnArr.push(`亮度${result[2].value}% `)
        // returnArr.push(`${getShuangSeWemMode(result[3].value)} `)
        returnArr.push(`${result[4].value}档 `)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`关`)
      }
      returnArr.push(`</div>`)
      break
    case '0FAA0D03':    //单色温驱动
      myArr = ['switchState', 'setBrightness', 'mode', 'duration']
      result = getDeviceActionStatus(myActions, myArr)
      if (result[0].value === '01') {
        returnArr.push(`<div class="myTagOpen">`)
        returnArr.push(`亮度${result[1].value}% `)
        // returnArr.push(`${getShuangSeWemMode(result[3].value)} `)
        returnArr.push(`${result[3].value}档`)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`关`)
      }
      returnArr.push(`</div>`)
      break
    case '0FAA0D04':    //开关控制盒
    case '0FAA0502':    //一路面板
    case '0FAA0504':    //一路联控面板
    case '0FAA0602':    //二路面板
    case '0FAA0604':    //二路联控面板
    case '0FAA0702':    //三路面板
    case '0FAA0704':    //三路联控面板
    case '0FAA0804':    //四路联控面板
    case '0FAA0213':    //机械手控制器
    case '0FAA0902':    //声光报警器
    case '0FAA8106':    //插卡取电
    case '0FAA8A09':    //多功能开关
    case '0FAA8A0A':    //卓悦面板
    case '0FAB0202':    //八路控制器
    case '0FAB0602':    //四路面板(雷达功能)
    case '0FAA0202':    //强电控制盒
    case '0FAA0203':    //弱电控制盒
    case '0FE60211':    //平移开窗器
    case '0FAA0211':    //推拉开窗器
    case '0FAA0511':    //移动开关插座
    case '0FE60206':    //取暖器（红杉树）现阶段只取开关, 其他状态后期补齐
      if (myActions.actions.controlState === '1') {
        returnArr.push(`<div class="myTagOpen">`)
        returnArr.push(`开`)
      } else if (myActions.actions.controlState === '2') {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`关`)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`未知`)
      }
      returnArr.push(`</div>`)
      break
    case '0FC80402':    //10A计量插座
    case '0FC80403':    //16A计量插座
      if (myActions.actions.controlState === '1') {
        returnArr.push(`<div class="myTagOpen">`)
        returnArr.push(`开`)
      } else if (myActions.actions.controlState === '2') {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`关`)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`未知`)
      }
      returnArr.push(`</div>`)
      break
    case '0FAA0E02':    //智能窗帘
    case '0FE60209':    //静音窗帘(丙申)
      myArr = ['position']
      if (myActions.actions.position) {
        returnArr.push(`<div class="myTagLight">`)
        returnArr.push(`开合度${parseInt(myActions.actions.position, 16)}% `)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`未知`)
      }
      returnArr.push(`</div>`)
      break
    case '0FBE0102':  //门磁
      myArr = ['fangChaiState', 'alarmState', 'dianya']
      result = getDeviceActionStatus(myActions, myArr)
      if (result[0].value) {
        returnArr.push(`<div class="myTagOpen">`)
        if (result[0].value === '01') {
          returnArr.push(`防拆开关故障 `)
        } else if (result[0].value === '02') {
          returnArr.push(`防拆开关正常 `)
        }
        returnArr.push(`${result[1].value === '01' ? '已开启' : '已关闭'} `)
        returnArr.push(`电量${getDianLiang(result[2].value)}`)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`未知`)
      }
      returnArr.push(`</div>`)
      break
    case '0FBE0402':  //人体红外
      myArr = ['fangChaiState', 'alarmState', 'dianya']
      result = getDeviceActionStatus(myActions, myArr)
      if (result[0].value) {
        returnArr.push(`<div class="myTagLight">`)
        if (result[0].value === '01') {
          returnArr.push(`防拆开关故障 `)
        } else if (result[0].value === '02') {
          returnArr.push(`防拆开关正常 `)
        }
        returnArr.push(`${result[1].value === '01' ? '感应有人' : '感应无人'} `)
        returnArr.push(`电量${getDianLiang(result[2].value)}`)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`未知`)
      }
      returnArr.push(`</div>`)
      break
    case '0FBF0202':  //德施曼锁
    case '0FBE0202':  //指纹锁（聪明屋）
    case '0FBE0203':  //指纹锁（六孚）
      myArr = ['dianya']
      result = getDeviceActionStatus(myActions, myArr)
      if (result[0].value) {
        returnArr.push(`<div class="myTagOpen">`)
        returnArr.push(`电量${getDianLiang(result[0].value)}%`)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`未知`)
      }
      returnArr.push(`</div>`)
      break
    case '0FAA0B02':  //灯带1.0
    case '0FAA0B03':  //灯带2.0
      // myArr = ['switchState']
      // result = getDeviceActionStatus(myActions, myArr)
      if (myActions.actions.controlState === '1') {
        returnArr.push(`<div class="myTagOpen">`)
        returnArr.push(`开`)
      } else if (myActions.actions.controlState === '2') {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`关`)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`未知`)
      }
      returnArr.push(`</div>`)
      break
    case '0FBE0702':  //烟雾探测器(弱电)
    case '0FBE0502':  //水浸传感器
      myArr = ['fangChaiState', 'alarmState', 'dianya']
      result = getDeviceActionStatus(myActions, myArr)
      if (result[0].value) {
        returnArr.push(`<div class="myTagLight">`)
        if (result[0].value === '01') {
          returnArr.push(`防拆开关故障 `)
        } else if (result[0].value === '02') {
          returnArr.push(`防拆开关正常 `)
        }
        returnArr.push(`${result[1].value === '01' ? '检测报警' : '检测正常'} `)
        returnArr.push(`电量${getDianLiang(result[2].value)}`)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`未知`)
      }
      returnArr.push(`</div>`)
      break
    case  '0FAA8102':   //燃气探测器(强电)
      myArr = ['alarmState']
      result = getDeviceActionStatus(myActions, myArr)
      if (result[0].value) {
        returnArr.push(`<div class="myTagLight">`)
        returnArr.push(`${result[0].value === '01' ? '检测报警' : '检测正常'} `)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`未知`)
      }
      returnArr.push(`</div>`)
      break
    case '0FAC0502':  // 智能空调面板
      // 空调
      // debugger
      if (deviceType.split('_')[1] === '1') {
        myArr = ['nowTemplate', 'nowHumidity', 'switchState', 'mode', 'temperature', 'fanSpeed']
        result = getDeviceActionStatus(myActions, myArr)
        if (result[2].value === '01') {
          returnArr.push(`<div class="myTagLight">`)
          returnArr.push(`室内温度${result[0].value}°C `)
          returnArr.push(`湿度${result[1].value}% | `)
          returnArr.push(`${getAirConditionMode(result[3].value)} `)
          returnArr.push(`${result[4].value}°C `)
          returnArr.push(`${getAirConditionFanSpeed(result[5].value)} `)
        } else if (result[2].value === '02') {
          returnArr.push(`<div class="myTagLight">`)
          returnArr.push(`室内温度${result[0].value}°C `)
          returnArr.push(`湿度${result[1].value}% 已关闭`)
        } else {
          returnArr.push(`<div class="myTagClose">`)
          returnArr.push(`未知`)
        }
        returnArr.push(`</div>`)
      } else if (deviceType.split('_')[1] === '2') {
        // 地暖
        myArr = ['nowTemplate', 'nowHumidity', 'switchState', 'temperature']
        result = getDeviceActionStatus(myActions, myArr)
        if (result[2].value === '01') {
          returnArr.push(`<div class="myTagLight">`)
          returnArr.push(`室内温度${result[0].value}°C `)
          returnArr.push(`湿度${result[1].value}% | `)
          returnArr.push(`${result[3].value}°C `)
        } else if (result[2].value === '02') {
          returnArr.push(`<div class="myTagLight">`)
          returnArr.push(`室内温度${result[0].value}°C `)
          returnArr.push(`湿度${result[1].value}% | 已关闭`)
        } else {
          returnArr.push(`<div class="myTagClose">`)
          returnArr.push(`未知`)
        }
        returnArr.push(`</div>`)
      } else if (deviceType.split('_')[1] === '3') {
        // 新风
        myArr = ['nowTemplate', 'nowHumidity', 'switchState', 'fanSpeed']
        result = getDeviceActionStatus(myActions, myArr)
        if (result[2].value === '01') {
          returnArr.push(`<div class="myTagLight">`)
          returnArr.push(`室内温度${result[0].value}°C `)
          returnArr.push(`湿度${result[1].value}% | `)
          returnArr.push(`${getAirConditionFanSpeed(result[3].value)} `)
        } else if (result[2].value === '02') {
          returnArr.push(`<div class="myTagLight">`)
          returnArr.push(`室内温度${result[0].value}°C `)
          returnArr.push(`湿度${result[1].value}% | 已关闭`)
        } else {
          returnArr.push(`<div class="myTagClose">`)
          returnArr.push(`未知`)
        }
        returnArr.push(`</div>`)
      }
      break
    case '0FAA0C02':    //晾衣架
      myArr = ['lightState', 'modeState']
      result = getDeviceActionStatus(myActions, myArr)
      returnArr.push(`<div class="myTagLight">`)
      returnArr.push(`${result[0].value === '01' ? '照明已开启' : '照明已关闭'} `)
      returnArr.push(`${getLiangYiJiaMode(result[1].value)} `)
      returnArr.push(`</div>`)
      break
    case '0FAA8105':    //86型人体感应面板
    case '0FAA8103':    //一氧化碳探测器 (可能有问题)
      myArr = ['alarmState', 'sosState']
      result = getDeviceActionStatus(myActions, myArr)
      returnArr.push(`<div class="myTagLight">`)
      returnArr.push(`${result[0].value === '01' ? '检测有人' : '检测无人'} `)
      if (result[1].value === '01') {
        returnArr.push(`SOS报警中`)
      }

      returnArr.push(`</div>`)
      break
    case '0FAC0202':    //空调面板
      if (myActions.actions.controlState === '1') {
        returnArr.push(`<div class="myTagOpen">`)
        returnArr.push(`开`)
      } else if (myActions.actions.controlState === '1') {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`关`)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`未知`)
      }
      returnArr.push(`</div>`)
      break
    case '0FAC0302':    //地暖面板
      if (myActions.actions.controlState === '1') {
        returnArr.push(`<div class="myTagOpen">`)
        returnArr.push(`开`)
      } else if (myActions.actions.controlState === '2') {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`关`)
      } else {
        returnArr.push(`<div class="myTagClose">`)
        returnArr.push(`未知`)
      }
      returnArr.push(`</div>`)
      break
    // case '0FAA8104':  //烟雾探测器(强电)
    // case '0FAA8A07':  //魔幻场景
    // case '0FAA8A08':  //随意贴
    // case '0FAA8A02':  //场景面板
    // case '0FAA8A03':  //液晶场景控制器
    // case '0FAA8A04':  //智能场景面板
    // case '0FAA8A05':  //六路场景（极享系列）
    // case '0FAA8A06':  //四路场景（极光系列）
    // case '0FAA8A10':  //六路场景
    // case '0FE60203':  //音乐背景器
    // case '0FE60202':  //红外学习仪
    // case '0FE60207':  //中央空调控制器
    // case '0FAD0207':  //智能空调控制器
    // case '0FBE0802':  //魔幻开关
    //   break
    default:
      returnArr.push(`<div class="myTagClose">`)
      returnArr.push(`未知`)
      returnArr.push(`</div>`)
      break
  }

  return returnArr.join('')
}

/**
 * 获取设备的状态数组对象
 * @param myActions 设备的属性列表
 * @param keyList 该设备的属性key的字符串数组
 * return 该设备属性数组
 */
function getDeviceActionStatus(myActions, keyList) {
  let resultArr = []
  for (let i = 0, len = keyList.length; i < len; i++) {
    resultArr.push({ key: keyList[i], value: '' })
    for (let j = 0, len2 = myActions.length; j < len2; j++) {
      if (myActions[j].actionsKey === keyList[i]) {
        resultArr[i].value = myActions[j].actionsValue
      }
    }
  }

  return resultArr
}

/**
 * 弱电设备通过电压获取电量
 * @param vol
 * @returns {string}
 */
function getDianLiang(vol) {
  let floatVol = parseFloat(vol)
  if (0 < floatVol && floatVol <= 2.5) {
    return '0%'
  } else if (2.5 < floatVol && floatVol <= 2.7) {
    return '25%'
  } else if (2.7 < floatVol && floatVol <= 2.9) {
    return '50%'
  } else if (2.9 < floatVol && floatVol <= 3.1) {
    return '75%'
  } else if (floatVol > 3.1) {
    return '100%'
  } else {
    return '未知'
  }
}

/**
 * 获取双色温模式
 * @param value
 */
function getShuangSeWemMode(value) {
  let modeStr = ''
  switch (value) {
    case '01':
      modeStr = '冷光呼吸'
      break
    case '02':
      modeStr = '暖光呼吸'
      break
    case '03':
      modeStr = '日光呼吸'
      break
    case '04':
      modeStr = '强冷暖呼吸'
      break
    case '05':
      modeStr = '弱冷暖呼吸'
      break
    case '06':
      modeStr = '冷暖呼吸交替'
      break
    case '07':
      modeStr = '冷暖渐变'
      break
    case '08':
      modeStr = '冷暖日光跳变'
      break
  }

  return modeStr
}

/**
 * 空调模式转换
 * @param value
 * @returns {string}
 */
function getAirConditionMode(value) {
  let modeStr = '未知'
  switch (value) {
    case 'COLD':
      modeStr = '制冷'
      break
    case 'HEAT':
      modeStr = '制热'
      break
    case 'DEHUMIDIFICATION':
      modeStr = '除湿'
      break
    case 'FAN':
      modeStr = '送风'
      break
    default:
      break
  }
  return modeStr
}

/**
 * 空调风速转换
 * @param value
 * @returns {string}
 */
function getAirConditionFanSpeed(value) {
  let fanSpeedStr = '未知'
  switch (value) {
    case 'LOW':
      fanSpeedStr = '低速'
      break
    case 'MID':
      fanSpeedStr = '中速'
      break
    case 'HIGH':
      fanSpeedStr = '高速'
      break
    case 'AUTO':
      fanSpeedStr = '自动'
      break
    default:
      break
  }
  return fanSpeedStr
}

/**
 * 晾衣架模式转换
 * @param value
 * @returns {string}
 */
function getLiangYiJiaMode(value) {
  let modeStr = ''
  switch (value) {
    case '00':
      modeStr = '未开启模式'
      break
    case '01':
      modeStr = '烘干模式中'
      break
    case '02':
      modeStr = '风干模式中'
      break
    case '04':
      modeStr = '消毒模式中'
      break
    case '08':
      modeStr = '负离子模式中'
      break
    default:
      modeStr = '未知'
      break
  }
  return modeStr
}
